<template>
    <div class="cetn_addline">
        <div>
            <div class="data-set-focus">
                <div>自定义航线：</div>
            </div>
            <div class="c_alItem0"><input maxlength="10" class="c_alItem_input" v-model="line_shows"/></div>
            <div class="c_alItem1"><span>&#xe64a;</span>&nbsp;组名将在首页以图标展示</div>
            <div class="c_alItem2">
                <span v-if="state.change||(!state.add&&!state.change)" @click="change">&#xe65a;</span>
                <span v-if="state.add||(!state.change&&!state.add)" @click="add_item">&#xe65e;</span>
            </div>
        </div>
        <div class="c_alItem3">
            <div class="c_alItem3_t">
                <div>始发</div>
                <div>到达</div>
                <div>经停</div>
            </div>
            <div class="c_alItem3_c" v-for="(key,index) in list">
                <div v-if="index=='ls'">
                    <div :class="{c_alItem3_s:true,spae_zindex:key.s.fous}">
                        <input type="text" :disabled="!state.add" v-model="key.s.name" @input="screen(index,'s')" @blur="restores(index,'s')">
                        <ariList :air="key.s.name" v-on:air_interface="airInterface" v-if="key.s.fous"></ariList>
                    </div>
                    <span>-</span>
                </div>
                <div v-if="index=='ls'">
                    <div :class="{c_alItem3_s:true,spae_zindex:key.d.fous}">
                        <input type="text" :disabled="!state.add" v-model="key.d.name" @input="screen(index,'d')" @blur="restores(index,'d')">
                        <ariList :air="key.d.name" v-on:air_interface="airInterface" v-if="key.d.fous"></ariList>
                    </div>
                    <span>-</span>
                </div>
                <div v-if="index=='ls'">
                    <div :class="{c_alItem3_s:true,spae_zindex:key.j.fous}">
                        <input type="text" :disabled="!state.add" v-model="key.j.name" @input="screen(index,'j')" @blur="restores(index,'j')">
                        <ariList :air="key.j.name" v-on:air_interface="airInterface" v-if="key.j.fous"></ariList>
                    </div>
                    <span></span>
                </div>
                <div v-if="index!='ls'">
                    <div :class="{c_alItem3_s:state.change,spae_zindex:key.s.fous}">
                        <input type="text" :disabled="!state.change" v-model="key.s.name" @input="screen(index,'s')" @blur="restores(index,'s')">
                        <ariList :air="key.s.name" v-on:air_interface="airInterface" v-if="key.s.fous"></ariList>
                    </div>
                    <span>-</span>
                </div>
                <div v-if="index!='ls'">
                    <div :class="{c_alItem3_s:state.change,spae_zindex:key.d.fous}">
                        <input type="text" :disabled="!state.change" v-model="key.d.name" @input="screen(index,'d')" @blur="restores(index,'d')">
                        <ariList :air="key.d.name" v-on:air_interface="airInterface" v-if="key.d.fous"></ariList>
                    </div>
                    <span>-</span>
                </div>
                <div v-if="index!='ls'">
                    <div :class="{c_alItem3_s:state.change,spae_zindex:key.j.fous}">
                        <input type="text" :disabled="!state.change" v-model="key.j.name" @input="screen(index,'j')" @blur="restores(index,'j')">
                        <ariList :air="key.j.name" v-on:air_interface="airInterface" v-if="key.j.fous"></ariList>
                    </div>
                    <span></span>
                </div>
                <p @click="itemDel(index)" v-if="index!='ls'">&#xe84b;</p>
            </div>
        </div>
        <div class="c_alItem4" v-if="tip.show">
            <span class="c_waring">&#xe64a;&nbsp;{{tip.name}}</span>
        </div>
        <div class="c_alItem4" v-if="state.change||state.add">
            <div class="personal-information-determine information-qe nice-btn-lBlue" @click="confirm">确定</div>
            <div class="personal-information-cancel information-of cancel-btn-ordinary" @click="cancel">取消</div>
        </div>
    </div>
</template>
<script>
    import ariList from './../../../component/airList.vue'
    export default{
        data(){
            return {
                line_shows:localStorage.getItem("_lisj"+document.getElementById("useName_n").innerText)!=null?localStorage.getItem("_lisj"+document.getElementById("useName_n").innerText):"自定义航线",
                tip:{
                    name:'',
                    show:false
                },
                linesData:JSON.parse(sessionStorage.getItem('linesData')),
                se_screen:'',
                airjw:JSON.parse(sessionStorage.getItem('airjw')),
                list:{},
                Olist:{},
                state:{
                    change:false,
                    add:false
                },
            }
        },
        watch:{
            line_shows:function(){
                localStorage.setItem("_lisj"+document.getElementById("useName_n").innerText,this.line_shows);
                document.getElementById("_lisj").innerText=this.line_shows;
            }
        },
        mounted:function () {
            this.mtd();
        },
        methods:{
            mtd:function () {
                $.ajax({
                    url:"/airRoute/findEmptyAirData",
                    type:'post',
                    dataType:"json",
                    success:(val)=>{
                        let data=val;
                        let arr={};
                        //筛选方法
                        let fil=(code)=>{
                            for(let i=0;i<this.airjw.success.airInfoDataList.length;i++){
                                if(this.airjw.success.airInfoDataList[i].iata==code){
                                    return this.airjw.success.airInfoDataList[i].airInfoName;
                                }
                            }
                        };
                        data.data.forEach((val)=>{
                            arr[val.id]={
                                airLine:val.airLine,
                                s:{
                                    name:fil(val.airLine.substr(0,3)),
                                    code:val.airLine.substr(0,3),
                                    fous:false
                                },
                                j:{
                                    name:val.airLine.length==6? '':fil(val.airLine.substr(3,3)),
                                    code:val.airLine.length==6? '':val.airLine.substr(3,3),
                                    fous:false
                                },
                                d:{
                                    name:val.airLine.length==6? fil(val.airLine.substr(3,3)):fil(val.airLine.substr(6,3)),
                                    code:val.airLine.length==6? val.airLine.substr(3,3):val.airLine.substr(6,3),
                                    fous:false
                                },
                            }
                        });
                        this.Olist=JSON.parse(JSON.stringify(arr));
                        this.list=JSON.parse(JSON.stringify(arr));
                        this.state.change=false;
                        this.state.add=false;
                    }
                });
            },
            add_item:function () {
                this.state.change=false;
                this.state.add=true;
                this.list.ls={
                    airLine:'',
                    s:{
                        name:'',
                        code:'',
                        fous:false
                    },
                    j:{
                        name:'',
                        code:'',
                        fous:false
                    },
                    d:{
                        name:'',
                        code:'',
                        fous:false
                    },
                };
            },
            restores:function(index,se){   //失去焦点关闭控件
                setTimeout(()=>{
                    $('#cityBox15').css('display','none');
                    if(this.list[index][se].code==""){
                        this.list[index][se]={
                            name:'',
                            code:'',
                            fous:false
                        };
                    }else{
                        if(this.list[index][se].name==""){
                            let obj={
                                name:'',
                                code:'',
                                fous:false
                            };
                            this.$set(this.list[index],se,obj);
                        }else{
                            for(let i=0;i<this.airjw.success.airInfoDataList.length;i++){
                                if(this.airjw.success.airInfoDataList[i].iata==this.list[index][se].code){
                                    if(this.airjw.success.airInfoDataList[i].airInfoName!=this.list[index][se].name){
                                        this.list[index][se]=JSON.parse(JSON.stringify(this.Olist[index][se]));
                                    }
                                }
                            }
                        }
                    }
                    this.list[index][se].fous=false;
                },200);
            },
            screen:function (index,se) {   //改变数据打开控件
                this.se_screen={
                    index:index,
                    se:se
                };
                this.list[index][se].fous=true;
                let objs=JSON.parse(JSON.stringify(this.list));
                this.list=objs;
            },
            airInterface:function (val) {    //接收数据
                if(this.se_screen.se=='s'){
                    if(val.name==this.list[this.se_screen.index].d.name||val.name==this.list[this.se_screen.index].j.name){
                        this.tip.name='机场不能重复';
                        this.tip.show=true;
                        setTimeout(()=>{this.tip.show=false;},1500)
                    }else {
                        this.list[this.se_screen.index].s.name=val.name;
                        this.list[this.se_screen.index].s.code=val.code;
                        this.list[this.se_screen.index].s.fous=false;
                    }
                }else if(this.se_screen.se=='j'){
                    if(val.name==this.list[this.se_screen.index].d.name||val.name==this.list[this.se_screen.index].s.name){
                        this.tip.name='机场不能重复';
                        this.tip.show=true;
                        setTimeout(()=>{this.tip.show=false;},1500)
                    }else {
                        this.list[this.se_screen.index].j.name=val.name;
                        this.list[this.se_screen.index].j.code=val.code;
                        this.list[this.se_screen.index].j.fous=false;
                    }
                }else if(this.se_screen.se=='d'){
                    if(val.name==this.list[this.se_screen.index].j.name||val.name==this.list[this.se_screen.index].s.name){
                        this.tip.name='机场不能重复';
                        this.tip.show=true;
                        setTimeout(()=>{this.tip.show=false;},1500)
                    }else {
                        this.list[this.se_screen.index].d.name=val.name;
                        this.list[this.se_screen.index].d.code=val.code;
                        this.list[this.se_screen.index].d.fous=false;
                    }
                }
            },
            itemDel:function (num) {
                if(confirm("确认要删除？")){
                    $.ajax({
                        url:"/airRoute/delete",
                        data:{
                            id:num
                        },
                        type:'post',
                        dataType:"json",
                        success:(val)=>{
                            if(val.success){
                                let ds=JSON.parse(JSON.stringify(this.list));
                                delete ds[num];
                                this.list=ds;
                                this.Olist=ds;
                                var airlineArray = this.list;
                                //清空原有模拟航线数组
                                DataList.data2=[];
                                DataList.point2=[];
                                var airport = this.airjw.success.airportCode;
                                for(var key in airlineArray){
                                    var addLine = airlineArray[key];
                                    var line = {};
                                    var point={};
                                    var leg=[];
                                    line.type=2;
                                    line.allLine='';
                                    point.type=2;
                                    var startPoint = [];
                                    var endPoint = [];
                                    var coordss = [];
                                    var startCode=addLine.s.code;
                                    var passCode=addLine.j.code;
                                    var endCode=addLine.d.code;
                                    if(passCode==''){
                                        var startWaypoint={};
                                        var endWaypoint={};
                                        if(startCode==airport){
                                            var startCity=airportMap[startCode];
                                            var endCity=airportMap[endCode];
                                            line.fromName=startCity.ctyChaNam;
                                            startWaypoint.name=startCity.ctyChaNam;
                                            line.toName=endCity.ctyChaNam;
                                            endWaypoint.name=endCity.ctyChaNam;
                                            startWaypoint.value=30;
                                            endWaypoint.value=30;
                                            point.name=endCity.ctyChaNam;
                                            //获取起止城市的坐标
                                            for(var i=0;i<cityCoordinateList.length;i++){
                                                var currCity = cityCoordinateList[i];
                                                if(currCity.cityName==startCity.ctyChaNam){
                                                    startPoint=currCity.cityCoordinatee.split(',');
                                                }else if(currCity.cityName==endCity.ctyChaNam){
                                                    endPoint=currCity.cityCoordinatee.split(',');
                                                    point.value=currCity.cityCoordinatee.split(',');
                                                    point.value.push('30');
                                                }
                                            }
                                            coordss.push(startPoint);
                                            coordss.push(endPoint);
                                            line.coords=coordss;
                                        }else{
                                            var startCity=airportMap[endCode];
                                            var endCity=airportMap[startCode];
                                            line.fromName=startCity.ctyChaNam;
                                            startWaypoint.name=startCity.ctyChaNam;
                                            line.toName=endCity.ctyChaNam;
                                            endWaypoint.name=endCity.ctyChaNam;
                                            startWaypoint.value=30;
                                            endWaypoint.value=30;
                                            point.name=endCity.ctyChaNam;
                                            //获取起止城市的坐标
                                            for(var i=0;i<cityCoordinateList.length;i++){
                                                var currCity = cityCoordinateList[i];
                                                if(currCity.cityName==startCity.ctyChaNam){
                                                    startPoint=currCity.cityCoordinatee.split(',');
                                                }else if(currCity.cityName==endCity.ctyChaNam){
                                                    endPoint=currCity.cityCoordinatee.split(',');
                                                    point.value=currCity.cityCoordinatee.split(',');
                                                    point.value.push('30');
                                                }
                                            }
                                            coordss.push(startPoint);
                                            coordss.push(endPoint);
                                            line.coords=coordss;
                                        }
                                        leg.push(startWaypoint);
                                        leg.push(endWaypoint);
                                        HBData.push(leg);
                                        DataList.data2.push(line);
                                        DataList.point2.push(point);
                                    }else {
                                        var passPoint = [];
                                        var point1={};
                                        point1.type=2;
                                        var startWaypoint={};
                                        var passWaypoint={};
                                        var endWaypoint={};
                                        startWaypoint.value=30;
                                        passWaypoint.value=30;
                                        endWaypoint.value=30;
                                        if(startCode==airport){//起飞本场
                                            var startCity=airportMap[startCode];
                                            var endCity=airportMap[endCode];
                                            var passCity=airportMap[passCode];
                                            line.fromName=startCity.ctyChaNam;
                                            startWaypoint.name=startCity.ctyChaNam;
                                            line.toName=passCity.ctyChaNam;
                                            passWaypoint.name=passCity.ctyChaNam;
                                            point.name=endCity.ctyChaNam;
                                            point1.name=passCity.ctyChaNam;
                                            leg.push(startWaypoint);
                                            leg.push(passWaypoint);
                                            HBData.push(leg);
                                            //获取起止城市的坐标
                                            for(var i=0;i<cityCoordinateList.length;i++){
                                                var currCity = cityCoordinateList[i];
                                                if(currCity.cityName==startCity.ctyChaNam){
                                                    startPoint=currCity.cityCoordinatee.split(',');
                                                }else if(currCity.cityName==endCity.ctyChaNam){
                                                    endPoint=currCity.cityCoordinatee.split(',');
                                                    point.value=currCity.cityCoordinatee.split(',');
                                                    point.value=point.value.push('30');
                                                }else if(currCity.cityName==passCity.ctyChaNam){
                                                    passPoint=currCity.cityCoordinatee.split(',');
                                                    point1.value=currCity.cityCoordinatee.split(',');
                                                    point1.value.push('30');
                                                }
                                            }
                                            coordss.push(startPoint);
                                            coordss.push(passPoint);
                                            line.coords=coordss;
                                            DataList.data2.push(line);
                                            line = {};
                                            leg=[];
                                            coordss=[];
                                            line.type=2;
                                            line.allLine='';
                                            line.fromName=passCity.ctyChaNam;
                                            passWaypoint.name=passCity.ctyChaNam;
                                            line.toName=endCity.ctyChaNam;
                                            endWaypoint.anem=endCity.ctyChaNam;
                                            coordss.push(passPoint);
                                            coordss.push(endPoint);
                                            line.coords=coordss;
                                            leg.push(passWaypoint);
                                            leg.push(endWaypoint);
                                            HBData.push(leg);
                                            DataList.data2.push(line);
                                            DataList.point2.push(point);
                                            DataList.point2.push(point1);
                                        }else if(endCode==airport){//到达本场
                                            var startCity=airportMap[endCode];
                                            var endCity=airportMap[startCode];
                                            var passCity=airportMap[passCode];
                                            line.fromName=startCity.ctyChaNam;
                                            startWaypoint.name=startCity.ctyChaNam;
                                            line.toName=passCity.ctyChaNam;
                                            passWaypoint.name=passCity.ctyChaNam;
                                            point.name=endCity.ctyChaNam;
                                            point1.name=passCity.ctyChaNam;
                                            leg.push(startWaypoint);
                                            leg.push(endWaypoint);
                                            HBData.push(leg);
                                            //获取起止城市的坐标
                                            for(var i=0;i<cityCoordinateList.length;i++){
                                                var currCity = cityCoordinateList[i];
                                                if(currCity.cityName==startCity.ctyChaNam){
                                                    startPoint=currCity.cityCoordinatee.split(',');
                                                }else if(currCity.cityName==endCity.ctyChaNam){
                                                    endPoint=currCity.cityCoordinatee.split(',');
                                                    point.value=currCity.cityCoordinatee.split(',');
                                                    point.value.push('30');
                                                }else if(currCity.cityName==passCity.ctyChaNam){
                                                    passPoint=currCity.cityCoordinatee.split(',');
                                                    point1.value=currCity.cityCoordinatee.split(',');
                                                    point1.value.push('30');
                                                }
                                            }
                                            coordss.push(startPoint);
                                            coordss.push(passPoint);
                                            line.coords=coordss;
                                            DataList.data2.push(line);
                                            line = {};
                                            coordss=[];
                                            leg=[];
                                            line.type=2;
                                            line.allLine='';
                                            line.fromName=passCity.ctyChaNam;
                                            passWaypoint.name=passCity.ctyChaNam;
                                            line.toName=endCity.ctyChaNam;
                                            endWaypoint.name=endCity.ctyChaNam;
                                            coordss.push(passPoint);
                                            coordss.push(endPoint);
                                            line.coords=coordss;
                                            leg.push(passWaypoint);
                                            leg.push(endWaypoint);
                                            HBData.push(leg);
                                            DataList.data2.push(line);
                                            DataList.point2.push(point);
                                            DataList.point2.push(point1);
                                        }else{//经停本场
                                            var startCity=airportMap[startCode];
                                            var endCity=airportMap[endCode];
                                            var passCity=airportMap[passCode];
                                            line.fromName=passCity.ctyChaNam;
                                            passWaypoint.name=passCity.ctyChaNam;
                                            line.toName=startCity.ctyChaNam;
                                            startWaypoint.name=startCity.ctyChaNam;
                                            point.name=startCity.ctyChaNam;
                                            point1.name=endCity.ctyChaNam;
                                            leg.push(passWaypoint);
                                            leg.push(startWaypoint);
                                            //获取起止城市的坐标
                                            for(var i=0;i<cityCoordinateList.length;i++){
                                                var currCity = cityCoordinateList[i];
                                                if(currCity.cityName==startCity.ctyChaNam){
                                                    startPoint=currCity.cityCoordinatee.split(',');
                                                    point.value=currCity.cityCoordinatee.split(',');
                                                    point.value.push('30');
                                                }else if(currCity.cityName==endCity.ctyChaNam){
                                                    endPoint=currCity.cityCoordinatee.split(',');
                                                    point1.value=currCity.cityCoordinatee.split(',');
                                                    point1.value.push('30');
                                                }else if(currCity.cityName==passCity.ctyChaNam){
                                                    passPoint=currCity.cityCoordinatee.split(',');
                                                }
                                            }
                                            coordss.push(passPoint);
                                            coordss.push(startPoint);
                                            line.coords=coordss;
                                            DataList.data2.push(line);
                                            line = {};
                                            coordss=[];
                                            line.type=2;
                                            line.allLine='';
                                            line.fromName=passCity.ctyChaNam;
                                            passWaypoint.name=passCity.ctyChaNam;
                                            line.toName=endCity.ctyChaNam;
                                            endWaypoint.name=endCity.ctyChaNam;
                                            coordss.push(passPoint);
                                            coordss.push(endPoint);
                                            line.coords=coordss;
                                            leg.push(passWaypoint);
                                            leg.push(endWaypoint);
                                            DataList.data2.push(line);
                                            DataList.point2.push(point);
                                            DataList.point2.push(point1);
                                            HBData.push(leg);
                                        }
                                    }
                                }
                                demo();
                            }
                        }
                    });
                }
            },
            change:function (){
                this.state.change=true;
//                this.state.add=true;
            },
            confirm:function () {
                $('#cityBox15').css('display','none');
                let td=true;
                if(Object.keys(this.Olist).length==0){
                    for(var key in this.list){
                        if(this.list[key].s.code==''||this.list[key].d.code==''){
                            this.tip.name='对不起，你有信息没有输入完整，必须包含始发和到达';
                            this.tip.show=true;
                            setTimeout(()=>{this.tip.show=false;},1500);
                            td=false;
                            break;
                        }else if(this.list[key].s.code!=this.airjw.success.airportCode&&this.list[key].d.code!=this.airjw.success.airportCode&&this.list[key].j.code!=this.airjw.success.airportCode){
                            this.tip.name='对不起，添加航线必须包含有本场';
                            this.tip.show=true;
                            setTimeout(()=>{this.tip.show=false;},1500);
                            td=false;
                            break;
                        }
                    }
                }else{
                    for(var key in this.Olist){
                        if(this.list[key].s.code==''||this.list[key].d.code==''){
                            this.tip.name='对不起，你有信息没有输入完整，必须包含始发和到达';
                            this.tip.show=true;
                            setTimeout(()=>{this.tip.show=false;},1500);
                            td=false;
                            break;
                        }else if(this.list[key].s.code!=this.airjw.success.airportCode&&this.list[key].d.code!=this.airjw.success.airportCode&&this.list[key].j.code!=this.airjw.success.airportCode){
                            this.tip.name='对不起，添加航线必须包含有本场';
                            this.tip.show=true;
                            setTimeout(()=>{this.tip.show=false;},1500);
                            td=false;
                            break;
                        }
                        if(this.list.ls.s.code!=""){
                            if(this.Olist[key].s.code==this.list.ls.s.code
                                &&this.Olist[key].d.code==this.list.ls.d.code
                                &&this.Olist[key].j.code==this.list.ls.j.code){
                                this.tip.name='对不起，你所添加的航线已经存在';
                                this.tip.show=true;
                                setTimeout(()=>{this.tip.show=false;},1500);
                                td=false;
                                break;
                            }else if(this.Olist[key].s.code==this.list.ls.s.code&&this.Olist[key].d.code==this.list.ls.d.code){
                                this.tip.name='对不起，你所添加的航线已经存在';
                                this.tip.show=true;
                                setTimeout(()=>{this.tip.show=false;},1500);
                                td=false;
                                break;
                            }
                        }
                    }
                }

                let xarr=[];
                let tarr=[];
                if(td){
                    for(var li in this.Olist){
                        if(this.Olist[li].s.code!=this.list[li].s.code||this.Olist[li].d.code!=this.list[li].d.code||this.Olist[li].j.code!=this.list[li].j.code){
                            xarr.push({
                                id:li,
                                airLine:this.list[li].s.code+this.list[li].j.code+this.list[li].d.code
                            })
                        }
                    }
                    if(this.list.ls!=undefined){
                        tarr.push(this.list.ls.s.code+this.list.ls.j.code+this.list.ls.d.code);   // 添加数据
                    }
                    if(xarr.length==0&&tarr.length==0){
                        this.state.change=false;
                        this.state.add=false;
                    }
                    if(xarr.length!=0){
                        $.ajax({
                            url:"/airRoute/edit",
                            data:{
                                airRouteList:JSON.stringify(xarr)
                            },
                            type:'post',
                            dataType:"json",
                            success:(val)=>{
                                if(val.success){
                                    this.Olist=JSON.parse(JSON.stringify(this.list));
                                    this.state.change=false;
                                    var airlineArray = this.list;
                                    //清空原有模拟航线数组
                                    DataList.data2=[];
                                    DataList.point2=[];
                                    var airport = this.airjw.success.airportCode;
                                    for(var key in airlineArray){
                                        var addLine = airlineArray[key];
                                        var line = {};
                                        var point={};
                                        var leg=[];
                                        line.type=2;
                                        line.allLine='';
                                        point.type=2;
                                        var startPoint = [];
                                        var endPoint = [];
                                        var coordss = [];
                                        var startCode=addLine.s.code;
                                        var passCode=addLine.j.code;
                                        var endCode=addLine.d.code;
                                        if(passCode==''){
                                            var startWaypoint={};
                                            var endWaypoint={};
                                            if(startCode==airport){
                                                var startCity=airportMap[startCode];
                                                var endCity=airportMap[endCode];
                                                line.fromName=startCity.ctyChaNam;
                                                startWaypoint.name=startCity.ctyChaNam;
                                                line.toName=endCity.ctyChaNam;
                                                endWaypoint.name=endCity.ctyChaNam;
                                                startWaypoint.value=30;
                                                endWaypoint.value=30;
                                                point.name=endCity.ctyChaNam;
                                                //获取起止城市的坐标
                                                for(var i=0;i<cityCoordinateList.length;i++){
                                                    var currCity = cityCoordinateList[i];
                                                    if(currCity.cityName==startCity.ctyChaNam){
                                                        startPoint=currCity.cityCoordinatee.split(',');
                                                    }else if(currCity.cityName==endCity.ctyChaNam){
                                                        endPoint=currCity.cityCoordinatee.split(',');
                                                        point.value=currCity.cityCoordinatee.split(',');
                                                        point.value.push('30');
                                                    }
                                                }
                                                coordss.push(startPoint);
                                                coordss.push(endPoint);
                                                line.coords=coordss;
                                            }else{
                                                var startCity=airportMap[endCode];
                                                var endCity=airportMap[startCode];
                                                line.fromName=startCity.ctyChaNam;
                                                startWaypoint.name=startCity.ctyChaNam;
                                                line.toName=endCity.ctyChaNam;
                                                endWaypoint.name=endCity.ctyChaNam;
                                                startWaypoint.value=30;
                                                endWaypoint.value=30;
                                                point.name=endCity.ctyChaNam;
                                                //获取起止城市的坐标
                                                for(var i=0;i<cityCoordinateList.length;i++){
                                                    var currCity = cityCoordinateList[i];
                                                    if(currCity.cityName==startCity.ctyChaNam){
                                                        startPoint=currCity.cityCoordinatee.split(',');
                                                    }else if(currCity.cityName==endCity.ctyChaNam){
                                                        endPoint=currCity.cityCoordinatee.split(',');
                                                        point.value=currCity.cityCoordinatee.split(',');
                                                        point.value.push('30');
                                                    }
                                                }
                                                coordss.push(startPoint);
                                                coordss.push(endPoint);
                                                line.coords=coordss;
                                            }
                                            leg.push(startWaypoint);
                                            leg.push(endWaypoint);
                                            HBData.push(leg);
                                            DataList.data2.push(line);
                                            DataList.point2.push(point);
                                        }else {
                                            var passPoint = [];
                                            var point1={};
                                            point1.type=2;
                                            var startWaypoint={};
                                            var passWaypoint={};
                                            var endWaypoint={};
                                            startWaypoint.value=30;
                                            passWaypoint.value=30;
                                            endWaypoint.value=30;
                                            if(startCode==airport){//起飞本场
                                                var startCity=airportMap[startCode];
                                                var endCity=airportMap[endCode];
                                                var passCity=airportMap[passCode];
                                                line.fromName=startCity.ctyChaNam;
                                                startWaypoint.name=startCity.ctyChaNam;
                                                line.toName=passCity.ctyChaNam;
                                                passWaypoint.name=passCity.ctyChaNam;
                                                point.name=endCity.ctyChaNam;
                                                point1.name=passCity.ctyChaNam;
                                                leg.push(startWaypoint);
                                                leg.push(passWaypoint);
                                                HBData.push(leg);
                                                //获取起止城市的坐标
                                                for(var i=0;i<cityCoordinateList.length;i++){
                                                    var currCity = cityCoordinateList[i];
                                                    if(currCity.cityName==startCity.ctyChaNam){
                                                        startPoint=currCity.cityCoordinatee.split(',');
                                                    }else if(currCity.cityName==endCity.ctyChaNam){
                                                        endPoint=currCity.cityCoordinatee.split(',');
                                                        point.value=currCity.cityCoordinatee.split(',');
                                                        point.value=point.value.push('30');
                                                    }else if(currCity.cityName==passCity.ctyChaNam){
                                                        passPoint=currCity.cityCoordinatee.split(',');
                                                        point1.value=currCity.cityCoordinatee.split(',');
                                                        point1.value.push('30');
                                                    }
                                                }
                                                coordss.push(startPoint);
                                                coordss.push(passPoint);
                                                line.coords=coordss;
                                                DataList.data2.push(line);
                                                line = {};
                                                leg=[];
                                                coordss=[];
                                                line.type=2;
                                                line.allLine='';
                                                line.fromName=passCity.ctyChaNam;
                                                passWaypoint.name=passCity.ctyChaNam;
                                                line.toName=endCity.ctyChaNam;
                                                endWaypoint.anem=endCity.ctyChaNam;
                                                coordss.push(passPoint);
                                                coordss.push(endPoint);
                                                line.coords=coordss;
                                                leg.push(passWaypoint);
                                                leg.push(endWaypoint);
                                                HBData.push(leg);
                                                DataList.data2.push(line);
                                                DataList.point2.push(point);
                                                DataList.point2.push(point1);
                                            }else if(endCode==airport){//到达本场
                                                var startCity=airportMap[endCode];
                                                var endCity=airportMap[startCode];
                                                var passCity=airportMap[passCode];
                                                line.fromName=startCity.ctyChaNam;
                                                startWaypoint.name=startCity.ctyChaNam;
                                                line.toName=passCity.ctyChaNam;
                                                passWaypoint.name=passCity.ctyChaNam;
                                                point.name=endCity.ctyChaNam;
                                                point1.name=passCity.ctyChaNam;
                                                leg.push(startWaypoint);
                                                leg.push(endWaypoint);
                                                HBData.push(leg);
                                                //获取起止城市的坐标
                                                for(var i=0;i<cityCoordinateList.length;i++){
                                                    var currCity = cityCoordinateList[i];
                                                    if(currCity.cityName==startCity.ctyChaNam){
                                                        startPoint=currCity.cityCoordinatee.split(',');
                                                    }else if(currCity.cityName==endCity.ctyChaNam){
                                                        endPoint=currCity.cityCoordinatee.split(',');
                                                        point.value=currCity.cityCoordinatee.split(',');
                                                        point.value.push('30');
                                                    }else if(currCity.cityName==passCity.ctyChaNam){
                                                        passPoint=currCity.cityCoordinatee.split(',');
                                                        point1.value=currCity.cityCoordinatee.split(',');
                                                        point1.value.push('30');
                                                    }
                                                }
                                                coordss.push(startPoint);
                                                coordss.push(passPoint);
                                                line.coords=coordss;
                                                DataList.data2.push(line);
                                                line = {};
                                                coordss=[];
                                                leg=[];
                                                line.type=2;
                                                line.allLine='';
                                                line.fromName=passCity.ctyChaNam;
                                                passWaypoint.name=passCity.ctyChaNam;
                                                line.toName=endCity.ctyChaNam;
                                                endWaypoint.name=endCity.ctyChaNam;
                                                coordss.push(passPoint);
                                                coordss.push(endPoint);
                                                line.coords=coordss;
                                                leg.push(passWaypoint);
                                                leg.push(endWaypoint);
                                                HBData.push(leg);
                                                DataList.data2.push(line);
                                                DataList.point2.push(point);
                                                DataList.point2.push(point1);
                                            }else{//经停本场
                                                var startCity=airportMap[startCode];
                                                var endCity=airportMap[endCode];
                                                var passCity=airportMap[passCode];
                                                line.fromName=passCity.ctyChaNam;
                                                passWaypoint.name=passCity.ctyChaNam;
                                                line.toName=startCity.ctyChaNam;
                                                startWaypoint.name=startCity.ctyChaNam;
                                                point.name=startCity.ctyChaNam;
                                                point1.name=endCity.ctyChaNam;
                                                leg.push(passWaypoint);
                                                leg.push(startWaypoint);
                                                //获取起止城市的坐标
                                                for(var i=0;i<cityCoordinateList.length;i++){
                                                    var currCity = cityCoordinateList[i];
                                                    if(currCity.cityName==startCity.ctyChaNam){
                                                        startPoint=currCity.cityCoordinatee.split(',');
                                                        point.value=currCity.cityCoordinatee.split(',');
                                                        point.value.push('30');
                                                    }else if(currCity.cityName==endCity.ctyChaNam){
                                                        endPoint=currCity.cityCoordinatee.split(',');
                                                        point1.value=currCity.cityCoordinatee.split(',');
                                                        point1.value.push('30');
                                                    }else if(currCity.cityName==passCity.ctyChaNam){
                                                        passPoint=currCity.cityCoordinatee.split(',');
                                                    }
                                                }
                                                coordss.push(passPoint);
                                                coordss.push(startPoint);
                                                line.coords=coordss;
                                                DataList.data2.push(line);
                                                line = {};
                                                coordss=[];
                                                line.type=2;
                                                line.allLine='';
                                                line.fromName=passCity.ctyChaNam;
                                                passWaypoint.name=passCity.ctyChaNam;
                                                line.toName=endCity.ctyChaNam;
                                                endWaypoint.name=endCity.ctyChaNam;
                                                coordss.push(passPoint);
                                                coordss.push(endPoint);
                                                line.coords=coordss;
                                                leg.push(passWaypoint);
                                                leg.push(endWaypoint);
                                                DataList.data2.push(line);
                                                DataList.point2.push(point);
                                                DataList.point2.push(point1);
                                                HBData.push(leg);
                                            }
                                        }
                                    }
                                    demo();
                                    this.Olist=JSON.parse(JSON.stringify(this.list));
                                    this.state.change=false;
                                    this.state.add=false;
                                }
                            }
                        });
                    }
                    if(tarr.length!=0){
                        $.ajax({
                            url:"/airRoute/add",
                            data:{
                                airlineList:JSON.stringify(tarr)
                            },
                            type:'post',
                            dataType:"json",
                            success:(val)=>{
                                if(val.success){
                                    this.state.change=false;
                                    this.state.add=false;
                                    this.mtd();
                                    var addLine = this.list.ls;
                                    var airport = this.airjw.success.airportCode;
                                    var line = {};
                                    var point={};
                                    var leg=[];
                                    line.type=2;
                                    line.allLine='';
                                    point.type=2;
                                    var startPoint = [];
                                    var endPoint = [];
                                    var coordss = [];
                                    var startCode=addLine.s.code;
                                    var passCode=addLine.j.code;
                                    var endCode=addLine.d.code;
                                    if(passCode==''){
                                        var startWaypoint={};
                                        var endWaypoint={};
                                        if(startCode==airport){
                                            var startCity=airportMap[startCode];
                                            var endCity=airportMap[endCode];
                                            line.fromName=startCity.ctyChaNam;
                                            startWaypoint.name=startCity.ctyChaNam;
                                            line.toName=endCity.ctyChaNam;
                                            endWaypoint.name=endCity.ctyChaNam;
                                            startWaypoint.value=30;
                                            endWaypoint.value=30;
                                            point.name=endCity.ctyChaNam;
                                            //获取起止城市的坐标
                                            for(var i=0;i<cityCoordinateList.length;i++){
                                                var currCity = cityCoordinateList[i];
                                                if(currCity.cityName==startCity.ctyChaNam){
                                                    startPoint=currCity.cityCoordinatee.split(',');
                                                }else if(currCity.cityName==endCity.ctyChaNam){
                                                    endPoint=currCity.cityCoordinatee.split(',');
                                                    point.value=currCity.cityCoordinatee.split(',');
                                                    point.value.push('30');
                                                }
                                            }
                                            coordss.push(startPoint);
                                            coordss.push(endPoint);
                                            line.coords=coordss;
                                        }else{
                                            var startCity=airportMap[endCode];
                                            var endCity=airportMap[startCode];
                                            line.fromName=startCity.ctyChaNam;
                                            startWaypoint.name=startCity.ctyChaNam;
                                            line.toName=endCity.ctyChaNam;
                                            endWaypoint.name=endCity.ctyChaNam;
                                            startWaypoint.value=30;
                                            endWaypoint.value=30;
                                            point.name=endCity.ctyChaNam;
                                            //获取起止城市的坐标
                                            for(var i=0;i<cityCoordinateList.length;i++){
                                                var currCity = cityCoordinateList[i];
                                                if(currCity.cityName==startCity.ctyChaNam){
                                                    startPoint=currCity.cityCoordinatee.split(',');
                                                }else if(currCity.cityName==endCity.ctyChaNam){
                                                    endPoint=currCity.cityCoordinatee.split(',');
                                                    point.value=currCity.cityCoordinatee.split(',');
                                                    point.value.push('30');
                                                }
                                            }
                                            coordss.push(startPoint);
                                            coordss.push(endPoint);
                                            line.coords=coordss;
                                        }
                                        leg.push(startWaypoint);
                                        leg.push(endWaypoint);
                                        HBData.push(leg);
                                        DataList.data2.push(line);
                                        DataList.point2.push(point);
                                    }else {
                                        var passPoint = [];
                                        var point1={};
                                        point1.type=2;
                                        var startWaypoint={};
                                        var passWaypoint={};
                                        var endWaypoint={};
                                        startWaypoint.value=30;
                                        passWaypoint.value=30;
                                        endWaypoint.value=30;
                                        if(startCode==airport){//起飞本场
                                            var startCity=airportMap[startCode];
                                            var endCity=airportMap[endCode];
                                            var passCity=airportMap[passCode];
                                            line.fromName=startCity.ctyChaNam;
                                            startWaypoint.name=startCity.ctyChaNam;
                                            line.toName=passCity.ctyChaNam;
                                            passWaypoint.name=passCity.ctyChaNam;
                                            point.name=endCity.ctyChaNam;
                                            point1.name=passCity.ctyChaNam;
                                            leg.push(startWaypoint);
                                            leg.push(passWaypoint);
                                            HBData.push(leg);
                                            //获取起止城市的坐标
                                            for(var i=0;i<cityCoordinateList.length;i++){
                                                var currCity = cityCoordinateList[i];
                                                if(currCity.cityName==startCity.ctyChaNam){
                                                    startPoint=currCity.cityCoordinatee.split(',');
                                                }else if(currCity.cityName==endCity.ctyChaNam){
                                                    endPoint=currCity.cityCoordinatee.split(',');
                                                    point.value=currCity.cityCoordinatee.split(',');
                                                    point.value=point.value.push('30');
                                                }else if(currCity.cityName==passCity.ctyChaNam){
                                                    passPoint=currCity.cityCoordinatee.split(',');
                                                    point1.value=currCity.cityCoordinatee.split(',');
                                                    point1.value.push('30');
                                                }
                                            }
                                            coordss.push(startPoint);
                                            coordss.push(passPoint);
                                            line.coords=coordss;
                                            DataList.data2.push(line);
                                            line = {};
                                            leg=[];
                                            coordss=[];
                                            line.type=2;
                                            line.allLine='';
                                            line.fromName=passCity.ctyChaNam;
                                            passWaypoint.name=passCity.ctyChaNam;
                                            line.toName=endCity.ctyChaNam;
                                            endWaypoint.anem=endCity.ctyChaNam;
                                            coordss.push(passPoint);
                                            coordss.push(endPoint);
                                            line.coords=coordss;
                                            leg.push(passWaypoint);
                                            leg.push(endWaypoint);
                                            HBData.push(leg);
                                            DataList.data2.push(line);
                                            DataList.point2.push(point);
                                            DataList.point2.push(point1);
                                        }else if(endCode==airport){//到达本场
                                            var startCity=airportMap[endCode];
                                            var endCity=airportMap[startCode];
                                            var passCity=airportMap[passCode];
                                            line.fromName=startCity.ctyChaNam;
                                            startWaypoint.name=startCity.ctyChaNam;
                                            line.toName=passCity.ctyChaNam;
                                            passWaypoint.name=passCity.ctyChaNam;
                                            point.name=endCity.ctyChaNam;
                                            point1.name=passCity.ctyChaNam;
                                            leg.push(startWaypoint);
                                            leg.push(endWaypoint);
                                            HBData.push(leg);
                                            //获取起止城市的坐标
                                            for(var i=0;i<cityCoordinateList.length;i++){
                                                var currCity = cityCoordinateList[i];
                                                if(currCity.cityName==startCity.ctyChaNam){
                                                    startPoint=currCity.cityCoordinatee.split(',');
                                                }else if(currCity.cityName==endCity.ctyChaNam){
                                                    endPoint=currCity.cityCoordinatee.split(',');
                                                    point.value=currCity.cityCoordinatee.split(',');
                                                    point.value.push('30');
                                                }else if(currCity.cityName==passCity.ctyChaNam){
                                                    passPoint=currCity.cityCoordinatee.split(',');
                                                    point1.value=currCity.cityCoordinatee.split(',');
                                                    point1.value.push('30');
                                                }
                                            }
                                            coordss.push(startPoint);
                                            coordss.push(passPoint);
                                            line.coords=coordss;
                                            DataList.data2.push(line);
                                            line = {};
                                            coordss=[];
                                            leg=[];
                                            line.type=2;
                                            line.allLine='';
                                            line.fromName=passCity.ctyChaNam;
                                            passWaypoint.name=passCity.ctyChaNam;
                                            line.toName=endCity.ctyChaNam;
                                            endWaypoint.name=endCity.ctyChaNam;
                                            coordss.push(passPoint);
                                            coordss.push(endPoint);
                                            line.coords=coordss;
                                            leg.push(passWaypoint);
                                            leg.push(endWaypoint);
                                            HBData.push(leg);
                                            DataList.data2.push(line);
                                            DataList.point2.push(point);
                                            DataList.point2.push(point1);
                                        }else{//经停本场
                                            var startCity=airportMap[startCode];
                                            var endCity=airportMap[endCode];
                                            var passCity=airportMap[passCode];
                                            line.fromName=passCity.ctyChaNam;
                                            passWaypoint.name=passCity.ctyChaNam;
                                            line.toName=startCity.ctyChaNam;
                                            startWaypoint.name=startCity.ctyChaNam;
                                            point.name=startCity.ctyChaNam;
                                            point1.name=endCity.ctyChaNam;
                                            leg.push(passWaypoint);
                                            leg.push(startWaypoint);
                                            //获取起止城市的坐标
                                            for(var i=0;i<cityCoordinateList.length;i++){
                                                var currCity = cityCoordinateList[i];
                                                if(currCity.cityName==startCity.ctyChaNam){
                                                    startPoint=currCity.cityCoordinatee.split(',');
                                                    point.value=currCity.cityCoordinatee.split(',');
                                                    point.value.push('30');
                                                }else if(currCity.cityName==endCity.ctyChaNam){
                                                    endPoint=currCity.cityCoordinatee.split(',');
                                                    point1.value=currCity.cityCoordinatee.split(',');
                                                    point1.value.push('30');
                                                }else if(currCity.cityName==passCity.ctyChaNam){
                                                    passPoint=currCity.cityCoordinatee.split(',');
                                                }
                                            }
                                            coordss.push(passPoint);
                                            coordss.push(startPoint);
                                            line.coords=coordss;
                                            DataList.data2.push(line);
                                            line = {};
                                            coordss=[];
                                            line.type=2;
                                            line.allLine='';
                                            line.fromName=passCity.ctyChaNam;
                                            passWaypoint.name=passCity.ctyChaNam;
                                            line.toName=endCity.ctyChaNam;
                                            endWaypoint.name=endCity.ctyChaNam;
                                            coordss.push(passPoint);
                                            coordss.push(endPoint);
                                            line.coords=coordss;
                                            leg.push(passWaypoint);
                                            leg.push(endWaypoint);
                                            DataList.data2.push(line);
                                            DataList.point2.push(point);
                                            DataList.point2.push(point1);
                                            HBData.push(leg);
                                        }
                                    }
                                    demo();
                                    this.mtd();
                                }else {
                                    this.tip.name='对不起，你所添加的航线已经存在';
                                    this.tip.show=true;
                                    setTimeout(()=>{this.tip.show=false;},1500);
                                }
                            }
                        })
                    }
                }
            },
            cancel:function () {
                $('#cityBox15').css('display','none');
                this.state.change=false;
                this.state.add=false;
                this.list=JSON.parse(JSON.stringify(this.Olist));
            }
        },
        components:{
            ariList:ariList
        }
    }
</script>
<style >
</style>
